<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/jBootsrapPage.css" />

<script type="text/javascript" src="${pageContext.request.contextPath }/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/scripts/jBootstrapPage.js"></script>

<style type="text/css">
body {
	margin-left:auto;
	margin-right:auto;
	background-color:#EEEEEE;
}
.navbar.navbar-default{
	background-color: #f8f8f8;
    border-color: #e7e7e7;
}
.navbar-expand-lg{
font-size:20px;
	font-weight:600;
	padding-left:60px;
}
.navbar-expand-lg li{
	padding-left:25px;
}
</style>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/scripts/jquery-1.7.2.js"></script>

<script type="text/javascript">
	$(function() {
		$("[name = rpList]:checkbox").attr("checked", false);
		$(".role").click(function() {
			//将所有的选项框设为全不选
			$("[name = rpList]:checkbox").attr("checked", false);
			
			var rps = $(this).attr("href");
			var rp = rps.split(",");
			//在输入框中填入角色名
			var roleName = $(this).text();
			$("#role_name").val(roleName);
			
			//将对应的选项框勾选
			for(var i = 0 ; i <rp.length ; i++){
				$("input:checkbox[value='"+rp[i]+"']").attr("checked",true);
			}
			return false;
		});
		
		$("#add_role").click(function() {
			//获取输入框中的角色名字
			var roleNames = "";
			var inputRoleName = $.trim($("#role_name").val());
			
			//获取现在所有的角色名
			$(".role").each(function(){
				roleNames+=$(this).text() + ","; 
			});
			
			//判断是否重名
			var roleName = roleNames.split(",");
			for(var i = 0 ; i <roleName.length-1 ; i++){
				if(inputRoleName==roleName[i]){
					//重名提示
					alert("重名啦");
					return false;
				}
			}
			
			//不重名则提交
			$("#role_rps_form").attr("action","rm-roleAdd");
			$("#role_rps_form").submit();
		});
		
		$("#modifi_role").click(function() {
			//获取输入框中的角色名字
			var roleNames = "";
			var inputRoleName = $.trim($("#role_name").val());
			
			//获取现在所有的角色名
			$(".role").each(function(){
				roleNames+=$(this).text() + ","; 
			});
			
			//判断名字是否存在
			var roleName = roleNames.split(",");
			var sign = 0;
			for(var i = 0 ; i <roleName.length-1 ; i++){
				if(inputRoleName==roleName[i]){
					sign = 1;
					break;
				}
			}
			
			//修改的角色不存在
			if(sign==0){
				alert("修改的角色不存在");
				return false;
			}
			
			//存在则提交
			$("#role_rps_form").attr("action","rm-roleModifi");
			$("#role_rps_form").submit();
		});
		
		
	});
</script>


</head>
<body>
	<nav class="navbar navbar-expand-lg navbar-light bg-faded">
  <div class="container">
	  <div class="navbar-header">
	      <a class="navbar-brand" >欢迎${sessionScope.user.userName}</a>
	  </div>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
       <ul class="navbar-nav">
         <li class="nav-item "><a class="nav-link " href="${pageContext.request.contextPath }/homepage.jsp">&nbsp;首页&nbsp;</a></li>
         <s:if test="'管理用户' in #session.rolePermission_name_list">
			 <li class="nav-item dropdown">
	          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink">用户管理</a>
	          <ul class="dropdown-menu"  aria-labelledby="navbarDropdownMenuLink">
	            <li><a class="dropdown-item" href="um-userManage">用户管理</a></li>
	            <li><a class="dropdown-item" href="rm-roleManage">角色管理</a></li>
	          </ul>
	        </li>
		</s:if>
        <li class="nav-item dropdown">
          <a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink2">器材管理</a>
          <ul class="dropdown-menu">
          	<s:if test="'管理器材' in #session.rolePermission_name_list">
				<li><a href="em-equipmentManage">器材管理</a></li>
				<li><a href="er-equipmentRent">器材租借</a></li>
				<li><a href="er-equipmentRent">器材归还</a></li>
			</s:if>
			<s:else>
				<h3>器材</h3>
				<li><a href="er-equipmentRent">器材租借</a></li>
			</s:else>
          </ul>
        </li>
        <li class="nav-item dropdown">
          <a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink3">管理场地<span class="caret"></span></a>
          <ul class="dropdown-menu">
          <s:if test="'管理场地' in #session.rolePermission_name_list">
			<li><a href="add_field.action">场地添加</a></li>
			<li><a href="field_modifyRental.action">租金修改</a></li>
			<li><a href="field_show.action">显示场地</a></li>
		</s:if>
		<s:else>
			<h3>场地</h3>
			<li><a href="fieldAll_record.action">显示场地</a></li>	
			<li><a href="fieldRent_order.action">显示租用记录</a></li>	
		</s:else>
          </ul>
        </li>
        <li class=" nav-item dropdown">
          <a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink4">赛事管理<span class="caret"></span></a>
          <s:if test="'管理赛事' in #session.rolePermission_name_list">
			<ul class="dropdown-menu">
				<li><a href="matchApply_findAll.action?currPage=1" >查看赛事申请表</a></li>
				<li><a href="matchApply_apply.action">新建赛事申请表</a></li>
				<li><a href="matchApply_examine.action?currPage=1">审核赛事申请表</a></li>
				<li><a href="matchApply_delete.action?currPage=1" >删除赛事申请表</a></li>
				<li><a href="matchInfo_findAll.action?currPage=1" >查看赛事信息表</a></li>
				<li><a href="matchInfo_listUpdate.action?currPage=1" >更新赛事信息表</a></li>
				<li><a href="matchInfo_delete.action?currPage=1">删除赛事信息表</a></li>
			</ul>
		</s:if>
		<s:else>
			<li><a href="matchApply_findAll.action?currPage=1" >查看赛事申请表</a></li>
			<li><a href="matchInfo_findAll.action?currPage=1">查看赛事信息表</a>	</li>
		</s:else>
        </li>
       </ul>
      </div>
            <%-- <div class="navbar-header">
	      <a class="navbar-brand pull-right" >${sessionScope.user.userName}</a>
	  </div> --%>
  </div>
</nav>
<br /><br />
	<div class='container'>
	<div>
		<table class="table" >
			<tr class="title">
				<td>角色名称</td>
				<td>操作</td>
			</tr>

			<!-- 遍历开始 -->
			<s:iterator value="#session.role_list" var="role">
				<tr class="list">
					<td><a class="role" href="<s:iterator value="#role.rps" var="rp"><s:property value="#rp.permissionId" />,</s:iterator>"><s:property value="#role.roleName" /></a><input type="hidden" value="<s:property value="#role.roleId" />"/></td>
					<td>
						<s:if test="#role.roleName == '普通用户'">
						</s:if>	
						<s:else>
							<a href="rm-roleDelete?deleteRoleId=<s:property value="#role.roleId"/>" onclick="javascript: return confirm('真的要删除吗？');">删除</a>
						</s:else>
					</td>
				</tr>
			</s:iterator>
			<!-- 遍历结束 -->
		</table>

	</div>
	
	<s:form id="role_rps_form" name="role_rps_form" action="" method="post">
		<s:checkboxlist name="rpList" list="#session.rp_list" id="rps_cbl"
			listValue="permissionName" listKey="permissionId">
		</s:checkboxlist>
		角色名：<input type="text" id="role_name" name="roleName"/>
		<input type="button" id="add_role" value="添加为新角色"/>
		<input type="button" id="modifi_role" value="修改"/>
		
	</s:form>
	
	</div>
	

</body>
</html>